#include <iostream>
using namespace std;
#include <windows.h>

typedef void (*pInit)(string, int);
typedef void (*pLogic)(void);
typedef void (*pGenerate)(void);

int main(int argc, char* argv[])
{
	if(argc <= 1)
	{
		cout << "Invalid parameters: use -h for help." << endl;
		exit(1);
	}

	int diff = 0;

	if(argv[2] != NULL)
		sscanf(argv[2], "%d", &diff);

	pInit create;
	pLogic RandomizeNumbers;
	pGenerate GenerateProblem;

	// Ladataan DLL-kirjasto
	HINSTANCE hinstLib = LoadLibrary(TEXT("mathlogic.dll"));
	if(hinstLib == NULL)
	{
		//cerr << "ERROR: unable to load DLL library." << endl;
		return 1;
	}

	// Haetaan funktion pointteri
	create = (pInit)GetProcAddress(hinstLib, "_init");
	if(create == NULL)
	{
		//cerr << "ERROR: unable to load DLL method _init()." << endl;
		return 1;
	}

	RandomizeNumbers = (pLogic)GetProcAddress(hinstLib, "_randomizeNumbers");
	if(RandomizeNumbers == NULL)
	{
		//cerr << "ERROR: unable to load DLL method _randomizeNumbers()." << endl;
		return 1;
	}

	GenerateProblem = (pGenerate)GetProcAddress(hinstLib, "_generateProblem");
	if(GenerateProblem == NULL)
	{
		//cerr << "ERROR: unable to load DLL method _generateProblem()." << endl;
		return 1;
	}

	// Funktioiden kutsunta...
	create(argv[1], diff);
	RandomizeNumbers();
	GenerateProblem();

	// Vapautetaan DLL-kirjasto
	FreeLibrary(hinstLib);

	return 0;
}